package com.vfa.fishing.object;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import android.util.Log;

import com.vfa.fishing.GameActivity;
import com.vfa.fishing.common.Constant;

public class Person extends AbstractObject {
     public boolean Visible;
     private boolean isFishing ;
        public float  speed = 5;
        public int type, Stage;
        public int direction;
        public int sideAppear;
        public int blood;// mau nguoi cau ca
        public int strength;// suc khoe nguoi cau ca,neu co suc khoe lon thi co the cau duoc ca lon
        public int lengthsOfline;// neu day cau dai thi co the cau ca o duoi tang sau
        private int DIRECTION_LEFT= 1;
        private int DIRECTION_RIGHT= 2;
        // Constructor
        public Person(int x,int y,TiledTextureRegion pTextureRegion,int sideApp){
            super(x,y,pTextureRegion,sideApp);
            type = GameActivity.rand.nextInt(3);
            sideAppear = sideApp;// huong xuat hien cua con ca
            if(sideAppear == Constant.LEFTSIDE){
                direction = Constant.RIGHT;
            }
            else if(sideAppear == Constant.RIGHTSIDE){
                direction = Constant.LEFT;
            }
            blood = 100;
            strength = 100;
            lengthsOfline = 80;
            this.kindOfObject = Constant.PERSON;
        }

//        public void update(Sprite sprite,float posX,float posY,int distance)
//        {
//            //update máu
//            //update streng
//            //update dây câu
//        	//if(posX < distance)
//        	this.setPosition(posX, posY);
//        }
        public void update(int target)
        {
            //update máu
            //update streng
            //update dây câu        	
        	int X= (int) (this.getX());
        	int direction = 0;
//        	Log.d("UpdateBoat", "target: "+target);
//        	Log.d("UpdateBoat", "width: "+this.getWidth());        	
        	if(target - X > 0)
        	{
        		X +=speed;
        		direction = DIRECTION_RIGHT;
        	}
        	else
        	{
        		X -= speed;// van toc la 2
        		direction = DIRECTION_LEFT;
        	}
        	
        	if(direction == DIRECTION_RIGHT)
        	{
        		if(X < (target - (this.getWidth()/2)))
        			this.setPosition(X, this.getY());
        	}
        	else
        	{
        		if(X >(target-(this.getWidth()/2)))
        			this.setPosition(X, this.getY());
        	}
    		
        }

        @Override
        public void Eat() {
            // TODO Auto-generated method stub

        }

        @Override
        public void update() {
            // TODO Auto-generated method stub

        }
        /**check xem nguoi buong cau duoc chua.khi tourch vao man hinh,nguoi buong cau se chay den vi tri tourch va buong cau*/
        private boolean checkFishing(){
            return true;
        }
        public void setFishingFlag(){
            isFishing = true;
        }

		@Override
		public void resetDirection() {
			// TODO Auto-generated method stub
			
		}
}
